<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-30">
			<view class="margin-30-0 flex-around" @click="$tools.navigateBack()">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">{{list1Name}}</view>
				<view style="width: 40rpx;"></view>
			</view>
			<view class="margin-30-0" v-if="web_on == 0">
				<u-tabs :list="list1" lineColor="#967C5E" @click="chooseTabs"></u-tabs>
			</view>
			<view class="margin-30-0" v-else>
				<u-tabs :list="list2" lineColor="#967C5E" @click="chooseTabs2"></u-tabs>
			</view>
			<!-- 商品列表 -->
			<template v-if="list1Name == '积分商城'">
				<goodsItem :list="list" :isBuy="false" @click="goToDetail"></goodsItem>
			</template>
			<template v-else-if="list1Name == '折扣商城'">
				<goodsItem :list="list" :isBuy="false" @click="goToDetail1"></goodsItem>
			</template>
			<template v-else>
				<view class="score-view-bg" @click="$tools.navigateTo('/pages/auspiciousness/taoist-temple-list')">
					<view style="height: 50rpx;"></view>
					<view class="padding-30">
						<view class="margin-30-0 fontSize-18 color-000 flex1 text-center">祈福</view>
					</view>
				</view>
			</template>
			<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"
				width="150px" height="150px" text="列表为空" textSize="18">
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	import scoreGoodsItem from "@/components/goods/score-goods.vue"
	import goodsItem from "@/components/goods/goods.vue"
	export default {
		components: {
			scoreGoodsItem,
			goodsItem
		},
		data() {
			return {
				list1: [{
						name: '积分商城',
						goods_type: 2
					},
					{
						name: '折扣商城',
						goods_type: 5
					}
				],
				list1Name: '积分商城',
				list2: [{
						name: '积分商城',
						goods_type: 2
					},
					{
						name: '折扣商城',
						goods_type: 5
					},
					{
						name: '祈福',
						goods_type: ''
					}
				],
				goods_type: 2,
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
				web_on:'', // 1开启, 0关闭
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getConfig()
			this.getScoreList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getScoreList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getScoreList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
			async getConfig(){
				let res = await this.$http.post(this.$api.config,{},{})
				console.log(res)
				if(res.code == 1){
					this.web_on = res.data.web_on
				}
			},
			// 跳转详情
			goToDetail(item) {
				this.$tools.navigateTo('/pages/shop/shop-goods-info?goods_id=' + item.id + '&pathCode=' + '积分商城')
			},
			goToDetail1(item) {
				this.$tools.navigateTo('/pages/shop/shop-goods-info?goods_id=' + item.id + '&pathCode=' + '折扣商城')
			},
			chooseTabs(e) {
				this.list1Name = e.name
				this.goods_type = e.goods_type
				this.page = 1
				this.limit = 10
				this.list = []
				this.getScoreList()
			},
			chooseTabs2(e) {
				this.list1Name = e.name
				if (this.list1Name == '选择道观') {
					return this.$tools.navigateTo('/pages/auspiciousness/taoist-temple-list')
				}
				this.goods_type = e.goods_type
				this.page = 1
				this.limit = 10
				this.list = []
				this.getScoreList()
			},
			// 列表
			async getScoreList() {
				this.$http.post(this.$api.goods_list, {
					page: this.page,
					limit: this.limit,
					goods_type: this.goods_type
				}, {
					token: true
				}).then(res => {
					this.list = [...this.list, ...res.data]
				}).finally(() => {
					// 停止当前页面下拉刷新
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.score-view-bg {
		width: 100%;
		min-height: 100vh;
		background: url('https://wudang.chunchuangkeji.cn/image/33.png') no-repeat;
		background-size: 100% 100%;
	}

	.phone-view {
		width: 60rpx;
		height: 60rpx;
		border-radius: 60rpx;
		background-color: #F0F0F0;
		flex-shrink: 0;
	}

	.header-bg-image {
		width: 100%;
		height: 800rpx;
	}
</style>